clear
//log using "\\file\UsersS$\sba144\Home\Desktop\Chapter One\RR_Replication\Table 3.smcl", replace
set more off
use "\\file\UsersW$\wrr15\Home\My Documents\My Files\SAMANGI BANDARANAYAKE\REPLICATION PAPER\REVISION FOR CRITICAL FINANCE REVIEW\DATA AND CODE\FILES FOR REVISED PAPER\paper.dta", replace

drop if DKD_First == 9
drop if year < 1979

gen yearr = year
snapspan country_id year DKD_First , gen(year0) replace
rename year year1
gen year = yearr


**// STSETTING the dataset
stset year1 , origin(time year0) id(country_id) failure(DKD_First) exit(time .)   

**// Model III
streg GDPgrowth_lag Infl  realintrate   depr tot creditgrowth  moralhak   ///
LegOrGer LegOrFre LegOrSca Africa Other LatinAmerica conav Ha, dist(exponential) nohr ///
robust cluster(country_id) time

gen aaa = e(sample)
keep country_id year year1 year0 aaa

sort country_id year 

save "\\file\UsersW$\wrr15\Home\My Documents\My Files\SAMANGI BANDARANAYAKE\REPLICATION PAPER\REVISION FOR CRITICAL FINANCE REVIEW\DATA AND CODE\FILES FOR REVISED PAPER\paper(modified).dta", replace

clear
use "\\file\UsersW$\wrr15\Home\My Documents\My Files\SAMANGI BANDARANAYAKE\REPLICATION PAPER\REVISION FOR CRITICAL FINANCE REVIEW\DATA AND CODE\FILES FOR REVISED PAPER\paper.dta"  
sort country_id year
merge country_id year using "\\file\UsersW$\wrr15\Home\My Documents\My Files\SAMANGI BANDARANAYAKE\REPLICATION PAPER\REVISION FOR CRITICAL FINANCE REVIEW\DATA AND CODE\FILES FOR REVISED PAPER\paper(modified).dta", 
sort country_id year
drop _merge
save "\\file\UsersW$\wrr15\Home\My Documents\My Files\SAMANGI BANDARANAYAKE\REPLICATION PAPER\REVISION FOR CRITICAL FINANCE REVIEW\DATA AND CODE\FILES FOR REVISED PAPER\paper(revised).dta",replace

clear
use "\\file\UsersW$\wrr15\Home\My Documents\My Files\SAMANGI BANDARANAYAKE\REPLICATION PAPER\REVISION FOR CRITICAL FINANCE REVIEW\DATA AND CODE\FILES FOR REVISED PAPER\pooled.dta", replace
sort country_id year
merge country_id year using "\\file\UsersW$\wrr15\Home\My Documents\My Files\SAMANGI BANDARANAYAKE\REPLICATION PAPER\REVISION FOR CRITICAL FINANCE REVIEW\DATA AND CODE\FILES FOR REVISED PAPER\paper(revised).dta" 
save "\\file\UsersW$\wrr15\Home\My Documents\My Files\SAMANGI BANDARANAYAKE\REPLICATION PAPER\REVISION FOR CRITICAL FINANCE REVIEW\DATA AND CODE\FILES FOR REVISED PAPER\common.dta",replace


**//summary statistic with set common observations
summ GDPgrowth_lag WGDPgrowth_lag IGDPgrowth_lag ///
if WGDPgrowth_lag !=. & IGDPgrowth_lag !=. & aaa == 1
summ Infl WInfl IInfl DInfl if WInfl !=. & IInfl !=. & DInfl !=. & aaa == 1
summ depr Wdepr Idepr Ddepr if Wdepr!=. & Idepr!=.& Ddepr!=. & aaa ==1
summ tot Wtot Dtot if Wtot!=. & Dtot!=. & aaa == 1
summ realintrate Wrealintrate Drealintrate if Wrealintrate!=. & Drealintrate!=. ///
& aaa == 1
summ creditgrowth Wcreditgrowth Gcreditgrowth if Wcreditgrowth!=. & ///
Gcreditgrowth!=. & aaa == 1
summ moralhak  Imoralhak if Imoralhak !=. & aaa == 1

//log close
